const app = getApp();
import { request} from '../../utils/request';
import config from '../../utils/config'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        custom:wx.getMenuButtonBoundingClientRect(),
        picUrl:config.picUrl,
        formData: {album_id: 1},
        areaCode:'',
        bankName:'',
        list:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        if('code' in options){
            this.setData({areaCode:options.code})
        }else{
            config.toast('未获取到位置参数',201,()=>{
                setTimeout(()=>{wx.navigateBack({delta:1})},1500)
            })
        }
    },
    search(){
        this.getList()
    },
    changeSearch(e){
        this.setData({bankName:e.detail.value})
    },
    clearKeywrod(){
        this.setData({bankName:'',list:[]})
    },
    getList(){
        wx.showLoading()
        request({
            url:"/miniprogram/lklpay/getBank",
            data:{areaCode:this.data.areaCode,bankName:this.data.bankName},
            type:'post',
        }).then(res=>{
            wx.hideLoading()
            if(res.code == 200) this.setData({list:res.data})
        })
    },
    chooseBank(e){
        var pages = getCurrentPages(); // 获取页面栈
        var currPage = pages[pages.length - 1]; // 当前页面
        var prevPage = pages[pages.length - 2]; // 上一个页面
        var {openningbankcode,openningbankname,clearingbankcode} = e.currentTarget.dataset
        prevPage.setData({
            openningBankCode: openningbankcode,
            openningBankName:openningbankname,
            clearingBankCode:clearingbankcode
        })
        wx.navigateBack({delta:1})

    }
})